home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 732 / pstools / postsplit / postsplit.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  6KB  |  284 lines

  1.  
  2. /*
  3.   Name:               postsplit.c
  4.   Processor:          Amiga 68000
  5.   Compiler directive: lc -L xxx.c
  6.   Creation Date:      4 Sept 92
  7.   Version:            1.02
  8.   Author:             I Parker
  9.  
  10.   Description Splits pagestream colour postscript output into separate files
  11.   anl part working
  12.  
  13.   Known bugs:- At 'End Page' key words, two cr's are placed
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18. #include <string.h>
  19.  
  20. #define UNLOCK 0
  21. #define LOCK 1
  22.  
  23. FILE *ifp, *ofp, *fopen();
  24. void Rout1(), Rout2(), Rout3(), Rout4(), Output(), Stop();
  25. char inline[300];
  26. char outline[300];
  27. int index,a,b;
  28.  
  29.  
  30. main (argc, argv)
  31. int argc;
  32. char *argv[];
  33. {
  34.     if(argc != 3)
  35.     {
  36.     printf("\033[33mpostsplit by I Parker V1.02\n");
  37.              /* \033[33m = prt blue */
  38.     printf("Usage:- postsplit file.ps ([cyan|magenta|yellow|black|spotcolour]\n");
  39.         printf("[anl|fnt])\033[31m\n"); 
  40.              /* \033[31m = reset */
  41.     }
  42.  
  43.     if(argv[2][0] == 'a' && argv[2][1] == 'n' && argv[2][2] == 'l')
  44.     {
  45.     Rout1(argv);
  46.     }
  47.        if(argv[2][0] == 'f' && argv[2][1] == 'n' && argv[2][2] == 't')
  48.     {
  49.     Rout3(argv);
  50.     }
  51.        if(argv[2][0] == 'n' && argv[2][1] == 'u' && argv[2][2] == 'l')
  52.    {
  53.    Rout4();
  54.    }
  55.     if(argc == 3)
  56.     {
  57.         Rout2(argv);
  58.     }
  59. } /* end of main */
  60.  
  61. void Rout1(anl) /* routine to analyse the file */
  62. char *anl[];
  63. {
  64. char name[40];
  65.  
  66.    if((ifp = fopen(anl[1],"r"))==NULL)
  67.      {
  68.        fprintf(stderr, "Error : Cannot open input file %s\n", strupr(anl[1]));
  69.        exit(-1);
  70.     }
  71.       strcpy(name,anl[1]);
  72.       strcat(name,".anl");
  73.  
  74.       if((ofp = fopen(name, "wb"))==NULL)
  75.         {
  76.         fprintf(stderr, "Error: Unable to open output file %s\n",name);
  77.         exit(1);
  78.         }
  79.           printf("postscript analysis routine\n");
  80.           while(fgets(inline,300,ifp)!=NULL) /* to end of file */
  81.            {
  82.            index = 0;
  83.             a = 0;
  84.                       for (index=0; inline[index] != '\0'; index++)
  85. switch(inline[index])
  86. {
  87.   case '%': { a=4; } break;
  88.  
  89.   case '!':  {  if(a==4)  {  a=30;  Output(inline[index]);  }  }  break;
  90.  
  91.   case '(':   {   a=2;   }   break;
  92.  
  93.   case '"':  {  if(a==2)  {  a=10;  Output(inline[index]);  }  }  break;
  94.  
  95.   default: if(a > 5) { Output(inline[index]); }
  96.  
  97. } /* end of switch */
  98.  } /* end of while - null */
  99.  
  100.       Stop();
  101. } /* end of rout1 */
  102.  
  103. void Rout2(spl) /* routine to split the file */
  104. char *spl[];
  105. {
  106. char name[40]; /* this is so that the o/p file name can be generated with */
  107.                /* a suffix attached */
  108. int index;
  109. int flag = UNLOCK;
  110. int countbig = 1; /* count beginings */
  111. int countend = 1; /* count endings */
  112. int preq = 0; /* page required */
  113. int pmax = 0; /* maximum page in file */
  114.  
  115. {
  116.     if(spl[2][0] == 'a' && spl[2][1] == 'n' && spl[2][2] == 'l')
  117.         return;
  118.     if(spl[2][0] == 'n' && spl[2][1] == 'u' && spl[2][2] == 'l')
  119.         return;
  120.     if(spl[2][0] == 'f' && spl[2][1] == 'n' && spl[2][2] == 't')
  121.         return;
  122.  
  123.     if((ifp = fopen(spl[1],"r"))==NULL) {
  124.     fprintf(stderr, "Error : Cannot open input file %s\n", strupr(spl[1]));
  125.         exit(-1);
  126.         }
  127.     strcpy(name,spl[1]); /* create o/p file name from i/p names */
  128.     strcat(name,".");
  129.     strcat(name,spl[2]);
  130.  
  131.     if((ofp = fopen(name, "wb"))==NULL) {
  132.     fprintf(stderr, "Error : Unable to open output file %s\n",name);
  133.     exit(1);
  134.     }
  135.    printf("Enter page number required \n");
  136.    scanf("%d",&preq);
  137.    preq = preq+1;
  138.    printf("Enter maximum page number in file \n");
  139.    scanf("%d",&pmax);
  140.    pmax = pmax+1;
  141.     printf("Splitting postscript file generating %s fragment\n",name);    
  142.     while(fgets(inline,300,ifp)!=NULL)
  143.      {
  144.            index = 0;
  145.             a = 0;
  146.          b = 0;
  147.                       for (index=0; inline[index] != '\0'; index++)
  148. {
  149.    if(countbig < 2)
  150.    {
  151.    Output(inline[index]);
  152.    }
  153.    if(preq == countbig)
  154.    {
  155.    Output(inline[index]);
  156.     }
  157.    if(preq == countend)
  158.    {
  159.    countbig=100;
  160.    }
  161.     if(pmax == countend)
  162.     {
  163.     Output(inline[index]);
  164.     }
  165. switch(inline[index])  /* fine phrase % Begin P*/
  166. {
  167.  case '%': { a=1; } break;
  168.  
  169.  case ' ': { if(a==1) a=2; if(a==7) a=8; } break;
  170.  
  171.  case 'B': { if(a==2) a=3;else a=0; } break;
  172.  
  173.  case 'e': { if(a==3) a=4;else a=0; } break;
  174.  
  175.  case 'g': { if(a==4) a=5;else a=0; } break;
  176.  
  177.  case 'i': { if(a==5) a=6;else a=0; } break;
  178.  
  179.  case 'n': { if(a==6) a=7;else a=0; } break;
  180.  
  181.  case 'P': { if(a==8) {flag = LOCK; a=9;countbig++;}else a=0;} break;
  182.  
  183.  default: break;
  184.  
  185. } /* end of switch */
  186. switch(inline[index])  /* fine phrase % End P*/
  187. {
  188. case '%': { b=11;} break;
  189.  
  190. case ' ': { if(b==11) b=12; if(b==15) b=16; } break;
  191.  
  192. case 'E': { if(b==12) b=13;else b=0; } break;
  193.  
  194. case 'n': { if(b==13) b=14;else b=0; } break;
  195.  
  196. case 'd': { if(b==14) b=15;else b=0; } break;
  197.  
  198. case 'P': { if(b==16) {b=17;}else b=0; } break;
  199.  
  200. case 'a': { if(b==17) {b=18;}else b=0;}break;
  201.  
  202. case 'g': { if(b==18) {b=19;}else b=0;}break;
  203.  
  204. case 'e': { if(b==19) {countend++;}else b=0;}break;
  205.  
  206. default: break;
  207.  
  208. } /* end of else */
  209. } /* end of for */
  210.     }
  211. }
  212.     Stop();
  213. } /* end of rout2 */
  214.  
  215. void Rout3(blc)
  216. char *blc[];
  217. {
  218. char name[40]; /* this is so that the o/p file name can be generated with */
  219.                /* a suffix attached */
  220. int index;
  221. int countfnt = 0;
  222. {
  223.     if((ifp = fopen(blc[1],"r"))==NULL) {
  224.     fprintf(stderr, "Error : Cannot open input file %s\n", strupr(blc[1]));
  225.         exit(-1);
  226.         }
  227.     strcpy(name,blc[1]); /* create o/p file name from i/p names */
  228.     strcat(name,".fnt");
  229.  
  230.     if((ofp = fopen(name, "wb"))==NULL) {
  231.     fprintf(stderr, "Error : Unable to open output file %s\n",name);
  232.     exit(1);
  233.     }
  234.    printf("Extracting adobe font data (other fonts must be done manualy)\n");
  235.     while(fgets(inline,300,ifp)!=NULL)
  236.      {
  237.            index = 0;
  238.             a = 0;
  239.                       for (index=0; inline[index] != '\0'; index++)
  240. {
  241.    if (a==2 && countfnt == 2)
  242.    {
  243.    a=0;
  244.    Output('%');
  245.    Output('!');
  246.    }
  247.     if( countfnt > 1)
  248.     {
  249.     Output(inline[index]);
  250.     }
  251.  
  252. switch(inline[index])  /* fine phrase % Begin P*/
  253. {
  254.  case '%': { a=1; } break;
  255.  
  256.  case '!': { if(a==1) {a=2;countfnt++;}} break;
  257.  
  258.  default: {a=0;break;}
  259. } /* end of switch */
  260.  
  261. } /* end of for */
  262.     }
  263. }
  264.     Stop();
  265. } /* end of rout3 */
  266.  
  267. void Rout4()
  268. {
  269. printf("rout4 not programmed\n");
  270. }
  271.  
  272. void Output(ili)
  273. char ili;
  274. {
  275. putc(ili,ofp);
  276.  
  277. }
  278.  
  279. void Stop()
  280. {
  281. fclose(ifp);
  282. fclose(ofp);
  283. exit();
  284. }